#define _CRT_SECURE_NO_WARNINGS 1
/**
*      author: Y_Yao
*      created: 2024-09-15 19:54:59
**/

#include<bits/stdc++.h>

using namespace std;
const int N = 2e5 + 7;
using LL = long long;
vector<LL> dp(2 * N, 0);
int n, Q;
LL sum;
LL nums[N];

LL count(LL k, LL sum)
{
    LL ret = 0;
    int i = k % n == 0 ? k / n : k / n + 1;
    if (i == 0) i = 1;
    k% n == 0 ? ret += k / n * sum : ret += (k / n) * sum + (dp[i + k % n - 1] - dp[i - 1]);
    return ret;
}

void solve()
{
    LL l, r;
    cin >> l >> r;

    LL left = count(l - 1, sum);
    LL right = count(r, sum);
    cout << right - left << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
    {
        cin >> n >> Q;

        for (int i = 1;i <= n;i++)
        {
            cin >> nums[i];
            dp[i] = dp[i - 1] + nums[i];
            sum += nums[i];
        }

        for (int i = n + 1;i < 2 * n;i++)
            dp[i] = dp[i - 1] + nums[i - n];

        while (Q--)
        {
            solve();
        }
        sum = 0;
        dp.clear();
    }

    return 0;
}